﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraLayout;
using DevExpress.XtraLayout.Utils;


namespace AccessControl.Utility.Report
{
	public partial class TextReportViewer : XtraForm
	{
		#region Fields

		readonly TextReportBuilder _reportBuilder;
		private readonly String _title;
		private readonly Boolean _showReportBuilder;

		#endregion

		#region Constructor

		public TextReportViewer(TextReportBuilder reportBuilder, Form mdiParent, string title,Boolean showReportBuilder)
		{

			InitializeComponent();

			//MdiParent = mdiParent;
			_reportBuilder = reportBuilder;
			WindowState = FormWindowState.Maximized;
			reportBuilder.TextReportCreated += ShowReport;
			_showReportBuilder = showReportBuilder;
			reportBuilder.Dock = DockStyle.Fill;
			layoutControlItemShowReportBuilder.Height = _reportBuilder.Height;
			layoutControlItemShowReportBuilder.Control = _reportBuilder;
			layoutControlItemShowReportBuilder.TextVisible = false;
			_title = title;

		}

		#endregion

		#region EventHandlers



		public override sealed string Text
		{
			get
			{
				return base.Text;
			}
			set
			{
				base.Text = value;
			}
		}

		#endregion

		#region Private Methods

		public void ShowReport()
		{
			printControl1.PrintingSystem = _reportBuilder.Report.PrintingSystem;
			_reportBuilder.Report.CreateDocument();
		}

		#endregion

		#region Event

		private void TextReportViewer_Load(object sender, EventArgs e)
		{
			
			Text = string.Format("{0}", _title);
			if (_showReportBuilder)
				return;
			layoutControlItemShowReportBuilder.HideToCustomization();
			var result=_reportBuilder.Report.PrintDialog();
			if (result==DialogResult.OK)
			Close();
		
		}

		#endregion
	}
}